import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressTest {
    public static void main(String[] args) {
        try {
            // 通过获取本机的方式创建一个 InetAddress 实例
            InetAddress localHost = InetAddress.getLocalHost();

            // 获取当前主机的名称
            String hostName = localHost.getHostName();
            System.out.println(hostName);
            // 获取本机的 IP 地址
            String hostAddress = localHost.getHostAddress();
            System.out.println(hostAddress);

            boolean reachable = localHost.isReachable(100);
            System.out.println(reachable);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
